Flash Article

Integrating Video into Macromedia Flash

Macromedia Training

Incorporating video into your Macromedia Flash files opens many possibilities for interactivity, including education, product demonstrations, accessibility, and remote communication.

Although video is available in other online formats, Flash simplifies the process of incorporating it into websites. You can easily incorporate robust video into your applications changing it into a native MovieClip object that you can manipulate and completely control.

In this tutorial, you'll explore how to effectively incorporate video into a Flash application, and explore some best practices.

This article covers just a small portion of the Flash MX 2004: Rich Media Design instructor-led course. If you like what you see and want to get the full experience, find a Macromedia Authorized Training Partner near you. Only at a Macromedia Authorized Training location will you learn from instructors thoroughly trained and certified by Macromedia. You can learn more in a few days with a certified instructor trainer than you can learn in a year with a book. Get the skills you need to get ahead— Macromedia Training and Certification.

Requirements

To complete this tutorial you will need to install the following software and files:

Macromedia Flash MX Professional 2004

Quicktime

A web server

Install a web server such as Apache, IIS, Netscape, according to your website's requirements.

Tutorials and sample files:

To use this tutorial, you should also be familiar with the basics for creating and running movies using Macromedia Flash MX 2004. For more resources, check out the Flash Developer Center video category.

There are three ways to add video to a website using Flash:

  • Embed it in a Flash document (results in a larger file size).
  • Use the Flash Professional media components to stream it from a server (reduces file size).
  • Link it to an external video file and export your Flash document as a QuickTime movie. Note that this technique is only useful if you are building QuickTime movies with Flash playback controls.

Embedding Video Directly in a Flash Document

Flash MX 2004 accepts any video file format supported by Apple QuickTime or Microsoft Direct Show. Supported formats include MOV, MPEG and AVI files. If you embed video directly in a Flash document, the file size of the SWF will increase whether or not the end user views the video. Flash does an amazing job of compressing video files, but file size can still increase significantly when embedding video.

You embed video in a Flash document by:

  • Importing a video file to the library.
  • Placing an instance of it in a MovieClip or on the main Timeline.

When you drag a video instance from the library to a MovieClip, a dialog box prompts you to extend the Timeline to the length of the video.

As a best practice, add video to a MovieClip on the main document’s Timeline, not to the main Timeline itself. Because MovieClips are completely independent of the main Timeline, you don’t have to extend the main document’s Timeline to accommodate the length of the video.

To import video into a Flash document:

  1. Select File > Import… > Import to Library as you would to import any file.
  2. Select the video file to import using the Import dialog box.
  3. Use the Video Import wizard to:
    • Embed the video.
    • Import the entire video or edit the video first and then import it.
    • Define a Compression profile so that the video is appropriate for your users’ Internet bandwidth.
One way to embed video in a Flash Document

Figure 1. One way to embed video in a Flash Document

Importing Video into a Flash document

To import video into a SWF, follow these steps:

  1. Create a new Flash file by clicking File >New.
  2. Import video to the library:

    • Select File > Import > Import to Library and select cyclers.mov from the directory that you unzipped the files to.
    • Select Embed video in the Macromedia Flash document in the wizard and go to the next screen.
    • Select Import the Entire Video and go to the next screen.
    • Leave the Compression Profile at its default setting and select Finish to import the video to the library.
  3. Embed video into a MovieClip:

    • Create a MovieClip symbol and name it mcVideo.
    • Remain in mcVideo’s Timeline and drag an instance of cyclers.mov from the library to the Stage.
    • Select Yes in the dialog box to extend the MovieClip’s Timeline to the length of the video.
  4. Add the MovieClip to the main document:

    • Return to the main document’s Timeline.
    • Drag an instance of mcVideo from the library to the Stage.
    • Define the following properties for the MovieClip instance:
      • Instance name: video_mc
      • Width: 190
      • Height:130
  5. Save and test the application:

    • Save and test the application to view the video.
    • Choose View > Bandwidth Profiler and note the file size
    • Close the SWF and FLA.

Using Flash Media Components

Components are prebuilt widgets that you can add to a Flash document with little to no ActionScript.

Flash MX Professional 2004 also includes a set of Media components that you can drag from the Components panel to the Stage to create a Media component instance.

Once you put a component on the Stage, you assign sound and video to it using the Component Inspector and modify its properties using the Property inspector.

Media components

Figure 2. Media components

Adding Streaming Media to a Media Component

Use the Component Inspector to describe the media to stream.

To view the Component Inspector:

  • Select the Media component instance on the Stage.
  • Select Launch Component Inspector from the Property inspector Parameters tab.

The Parameters tab is available in the Property inspector when you select a Media component on the Stage.

Launch Component Inspector

Fig 3. Launch Component Inspector

Using the Component Inspector

Use the Parameters tab in the Component Inspector to specify the following for a Media Component instance:

  • The media’s file format
  • A URL from which to stream sound or video
  • Assign how the media should display in the component
Parameters tab in the Component Inspector

Fig 4. Parameters tab in the Component Inspector

Note: The Binding and Schema tabs are beyond the scope of this article. Developers use them to program a component.

Streaming Media File Formats

Flash Media components support two file types:

  • MP3 files to stream sound
  • FLV files to stream video

Many programs, including Flash, can compress sound into an MP3 format.

FLV is the Flash file format for streaming video. You can export video to create a FLV using Flash or another video editing program that supports the FLV format.

Example Usage

Drag an instance of the Media Playback component to the Stage to do the following:

  • Display a presentation screen when streaming video or sound.
  • Include playback controls at the bottom of the screen for user control.

Once on the Stage, define the component X,Y origin and size using the Property inspector and add media to the component by specifying a streaming file type and a URL to stream using the Component Inspector Parameters tab.

Exporting FLV files

Export a video file using Flash to create an FLV file.

To export a video to a FLV:

  1. Double-click on the video in the library to display the Embedded Video Properties dialog box, as shown in Figure 5.

    Embedded Video Properties dialog box

    Figure 5. Embedded Video Properties dialog box

  2. Select Export…
  3. Save the exported file to a new name with an FLV extension in the Export FLV dialog box.

    Export FLV dialog box

    Figure 6. Export FLV dialog box

Streaming Video

During this walkthrough, you will export video to create a FLV file, add a Media Playback component instance to a document, and select the FLV file to stream in the instance.

  1. Create a new Flash document.
  2. Export video:

    1. Import cyclers.mov from the directory where you unzipped the files to the library.
    2. Double-click cyclers.mov in the library to view its Embedded Video Properties. Ensure that you click the movie icon and not the text, otherwise, you will rename the text.
    3. Select Export.
    4. Use the Export FLV dialog box to save the exported file as cyclers.flv in the {webroot}.

      Note: If you are using Microsoft Internet Information Server (IIS), the web root is typically, c:\inetpub\wwwroot.

    5. Click Save and OK.
    6. Delete cyclers.mov in the library to maintain minimum document size.

  3. Add a Video Playback component:

    1. Drag an instance of the MediaPlayback component from the Components panel to the Stage.
    2. Use the Property inspector to define the component’s properties:

      • Width: 190
      • Height:130
      • X: 139
      • Y: 132

  4. Add video to the Video Playback component:

    1. Select the component instance on the Stage and click Launch Component Inspector on the Parameters tab of the Property inspector.

      Note: This automatically opens the Component Inspector panel in the docked panels.

    2. On the Component Inspector panel, select the FLV file type for the streaming media.
    3. Enter http://localhost/cyclers.flv in the URL field to stream the cyclers.flv file from that location.

  5. Save and test the application:

    1. Save and test the application.
    2. View the streaming video.
    3. Choose View > Bandwidth profiler and note how much smaller the video file is.

  6. Close the SWF and FLA

Summary

This article focuses on two ways of importing video into Flash:

  • Embedding the video directly into a Flash document
  • Using the media components.

The media components result in much smaller file sizes because the video is steamed down from a server; in addition they provide convenient user controls. To stream from a server, you must export the video as an FLV file from the Flash environment.

Embedding video into a Flash document is inherently more flexible because you can easily sync the video to animations or actions occurring on a Flash timeline. If you do embed video, it is a best practice to store the video in a separate MovieClip timeline because it allows you to more easily manipulate the video.